package dp;

import java.util.List;

public class leetCode120_minimumTotal {
    // dp[i][j] 表示 （i，j，第i行，第j列）点到底边的最小路径
    // dp[i][j]=min(dp[i+1][j],dp[i+1][j+1])+triangle[i][j]
    public int minimumTotal(List<List<Integer>> triangle) {
        int n = triangle.size();
        int[][] dp = new int[n + 1][n + 1];
        for (int i = n - 1; i >= 0 ; i--) {
            for (int j = 0; j <= i ; j++) {
                dp[i][j] = Math.min(dp[i + 1][j],dp[i + 1][j + 1]) + triangle.get(i).get(j);
            }
        }
        return dp[0][0];

    }
}
